package com.qianfeng.openapi.controller;

import com.github.pagehelper.PageInfo;
import com.qianfeng.openapi.bean.AjaxMessage;
import com.qianfeng.openapi.bean.TableData;
import com.qianfeng.openapi.pojo.Recharge;
import com.qianfeng.openapi.service.RechargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sys/recharge")
public class RechargeController {
    @Autowired
    private RechargeService rechargeService;

    @RequestMapping("/add")
    public AjaxMessage insetRecharge(Recharge recharge){
        rechargeService.insetRecharge(recharge);
        return new AjaxMessage(true,"添加成功");
    }

    @RequestMapping("/del")
    public AjaxMessage deleteRechargeById(int[] ids){
        rechargeService.deleteRechargeById(ids);
        return new AjaxMessage(true,"删除成功");
    }

    @RequestMapping("/update")
    public AjaxMessage updateRecharge(Recharge recharge){
        rechargeService.updateRecharge(recharge);
        return new AjaxMessage(true,"修改成功");
    }

    @RequestMapping("/table")
    public TableData<Recharge> getAllRecharge(int page, int limit, Recharge recharge){
        PageInfo<Recharge> pageInfo=rechargeService.getAllRecharge(page, limit, recharge);
        TableData<Recharge> tableData=new TableData<>();
        tableData.setCode(0);
        tableData.setMsg("成功");
        tableData.setCount(pageInfo.getTotal());
        tableData.setData(pageInfo.getList());
        return tableData;
    }

}
